<?php
require("conn.php");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$sid = $_POST["sid"];
$published = $_POST["published"];
$image =  $_POST["image"];
$tag = $_POST["tag"];

$vi_title=$_POST["vi_title"];
$vi_summary=$_POST["vi_summary"];
$vi_content=$_POST["vi_content"];
$en_title=$_POST["en_title"];
$en_summary= $_POST["en_summary"];
$en_content=$_POST["en_content"];
$created_date= date("Y/m/d");
$user_id = $_SESSION["UserID"];

$sql=sprintf("insert into tblarticle (section_id,published,image,tag,vi_title,vi_summary,vi_content,en_title,en_summary,en_content,created_date,user_id)   values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
	GetSQLValueString($sid,"int"),																																	  
	GetSQLValueString($published,"int"),
	GetSQLValueString($image,"text"),
	GetSQLValueString($tag,"text"),
	GetSQLValueString($vi_title,"text"),
	GetSQLValueString($vi_summary,"text"),
	GetSQLValueString($vi_content,"text"),
	GetSQLValueString($en_title,"text"),
	GetSQLValueString($en_summary,"text"),
	GetSQLValueString($en_content,"text"),
	GetSQLValueString($created_date,"date"),
	GetSQLValueString($user_id,"int"));

$rs=mysql_query($sql);
			 
			if(!$rs)
			{
				?>
				<script language="javascript">
					alert("Không thêm được vài viết!");
					window.location="article";
				</script>
				<?php
			}
			else
			{
				
				?>
				<script language="javascript">
				alert("Thêm bài viết thành công!");
				window.location="article";
				</script>
				<?php
			}

		

?>
